import { defHttp } from '/@/utils/http/axios';
import { getMenuListResultModel, Permission } from './model/menuModel';

enum Api {
  GetMenuList = '/inyaa-admin/permission/findMenuList',
  FindMenuList = '/inyaa-admin/permission/list',
  SvaeMenuList = '/inyaa-admin/permission/save',
  DeleteMenuList = '/inyaa-admin/permission/delete',

  findWebMenuList = '/inyaa-admin/menu/list',
  getWebMenu = '/inyaa-admin/menu/findMenuList',
  saveWebMenu = '/inyaa-admin/menu/save',
  deleteWebMenu = '/inyaa-admin/menu/delete',
}

/**
 * @description: Get user menu based on id
 */

export const getMenuList = (enable) => {
  enable = enable === 1 ? 1 : null;
  return defHttp.get<getMenuListResultModel>({
    url: Api.GetMenuList,
    params: {
      enable: enable,
    },
  });
};
export const saveMenu = (params: Permission) => {
  return defHttp.post<getMenuListResultModel>({ url: Api.SvaeMenuList, params });
};
export const deleteMenu = (params: Permission) => {
  return defHttp.post<getMenuListResultModel>({ url: Api.DeleteMenuList, params });
};
export const findMenuList = () => {
  return defHttp.get<getMenuListResultModel>({ url: Api.FindMenuList, params: { parentId: 0 } });
};

export const getWebMenuList = (enable) => {
  enable = enable === true ? true : null;
  return defHttp.get<getMenuListResultModel>({
    url: Api.getWebMenu,
    params: {
      enable: enable,
    },
  });
};

export const saveWebMenu = (params: Permission) => {
  return defHttp.post<getMenuListResultModel>({ url: Api.saveWebMenu, params });
};
export const deleteWebMenu = (params: Permission) => {
  return defHttp.post<getMenuListResultModel>({ url: Api.deleteWebMenu, params });
};
export const findWebMenuList = () => {
  return defHttp.get<getMenuListResultModel>({ url: Api.findWebMenuList, params: { parentId: 0 } });
};
